//按钮事件新增或编辑
var BEF4F0_type = "";
//其他页面传到本页面参数
var BEF4F0_param = {};
//暂时没用
var BEF4F0_validate = "";
//当前触发按钮
var BEF4F0_btn = "";

/*定义下拉框集合定义*/
/*declare select options begin*/
var BEF4F0_ary_TABLE_ID = null;
var BEF4F0_ary_BTN_POS = [{"MAIN_ID":"0","CN_NAME":"表格上端"},{"MAIN_ID":"1","CN_NAME":"表格下端"},{"MAIN_ID":"2","CN_NAME":"表格操作列"}];
var BEF4F0_ary_TO_URL = null;
var BEF4F0_ary_TO_URL_TYPE = [{"MAIN_ID":"-1","CN_NAME":""},{"MAIN_ID":"0","CN_NAME":"系统内弹窗"},{"MAIN_ID":"1","CN_NAME":"系统内tab页"},{"MAIN_ID":"2","CN_NAME":"浏览器窗口"}];
var BEF4F0_ary_RUN_PROC = null;

/*declare select options end*/

//输入框默认值
function BEF4F0_input_default(){
	/*时间格式初始化*/
	/*form datetime init begin*/
    if($("#BEF4F0_CREATE_DATE").val() == "")
    {
        $("#BEF4F0_CREATE_DATE").val(new Date().Format('yyyy-MM-dd hh:mm:ss'));
    }
    laydate.render({
        elem: '#BEF4F0_CREATE_DATE',
        type: 'datetime',
        trigger: 'click'
    });
	
    /*form datetime init end*/
	//所有输入框设置默认值
	/*Input Default Begin*/
	$("#BEF4F0_BTN_POS").val("0");
	$("#BEF4F0_TO_URL_TYPE").val("-1");
	$("#BEF4F0_S_SORT").val("0");
	/*Input Default End*/
}

//主从表传递参数
function BEF4F0_param_set(){
	/*Main Subsuv Table Param Begin*/
    $("#BEF4F0_find_TABLE_ID_cn_name").val("");
    $("#BEF4F0_find_TABLE_ID").val("-1");
    $("#BEF4F0_Clear_TABLE_ID").show();
    $("#BEF4F0_Ope_TABLE_ID").show();
    if(BEF4F0_param.hasOwnProperty("TABLE_ID_cn_name"))
        $("#BEF4F0_find_TABLE_ID_cn_name").val(s_decode(BEF4F0_param["TABLE_ID_cn_name"]));
    if(BEF4F0_param.hasOwnProperty("TABLE_ID"))
        $("#BEF4F0_TABLE_ID").val(BEF4F0_param["TABLE_ID"]);
    if(BEF4F0_param.hasOwnProperty("hidden_find") && BEF4F0_param.hasOwnProperty("TABLE_ID_cn_name")){
        $("#BEF4F0_Ope_TABLE_ID").hide();
        $("#BEF4F0_Clear_TABLE_ID").hide();
    }
	
	/*Main Subsuv Table Param end*/

	/*父页面查询条件参数传递至子页面并赋值*/
	/*Get Find Select param bgein*/
	if(BEF4F0_param.hasOwnProperty("TABLE_ID"))
    	$("#BEF4F0_TABLE_ID").val(BEF4F0_param["TABLE_ID"]);
	if(BEF4F0_param.hasOwnProperty("TABLE_ID_cn_name"))
    	$("#BEF4F0_find_TABLE_ID_cn_name").val(BEF4F0_param["TABLE_ID_cn_name"]);
	
	/*Get Find Select param end*/
}

//业务逻辑数据开始
function BEF4F0_t_btn_expand_biz_start(inputdata) {
	BEF4F0_param = inputdata;
	layer.close(ly_index);
    /*biz begin*/
    var inputdata = {
        "param_name": "N01_t_table_column$table_id",
        "session_id": session_id,
        "login_id": login_id
    };
    ly_index = layer.load();
    get_ajax_baseurl(inputdata, "BEF4F0_get_N01_t_table_column$table_id");
	
    /*biz end*/
}

/*biz step begin*/
function BEF4F0_format_TABLE_ID(value, row, index) {
    var objResult = value;
    for(i = 0; i < BEF4F0_ary_TABLE_ID.length; i++) {
        var obj = BEF4F0_ary_TABLE_ID[i];
        if (obj[GetLowUpp("main_id")].toString() == value.toString()) {
            objResult = s_decode(obj[GetLowUpp("cn_name")]);
            break;
        }
    }
    return objResult;
}

function BEF4F0_format_BTN_POS(value, row, index) {
    var objResult = value;
    for(i = 0; i < BEF4F0_ary_BTN_POS.length; i++) {
        var obj = BEF4F0_ary_BTN_POS[i];
        if (obj[GetLowUpp("main_id")].toString() == value.toString()) {
            objResult = s_decode(obj[GetLowUpp("cn_name")]);
            break;
        }
    }
    return objResult;
}

function BEF4F0_format_TO_URL(value, row, index) {
    var objResult = value;
    for(i = 0; i < BEF4F0_ary_TO_URL.length; i++) {
        var obj = BEF4F0_ary_TO_URL[i];
        if (obj[GetLowUpp("main_id")].toString() == value.toString()) {
            objResult = s_decode(obj[GetLowUpp("cn_name")]);
            break;
        }
    }
    return objResult;
}

function BEF4F0_format_TO_URL_TYPE(value, row, index) {
    var objResult = value;
    for(i = 0; i < BEF4F0_ary_TO_URL_TYPE.length; i++) {
        var obj = BEF4F0_ary_TO_URL_TYPE[i];
        if (obj[GetLowUpp("main_id")].toString() == value.toString()) {
            objResult = s_decode(obj[GetLowUpp("cn_name")]);
            break;
        }
    }
    return objResult;
}

function BEF4F0_format_RUN_PROC(value, row, index) {
    var objResult = value;
    for(i = 0; i < BEF4F0_ary_RUN_PROC.length; i++) {
        var obj = BEF4F0_ary_RUN_PROC[i];
        if (obj[GetLowUpp("main_id")].toString() == value.toString()) {
            objResult = s_decode(obj[GetLowUpp("cn_name")]);
            break;
        }
    }
    return objResult;
}

function BEF4F0_get_N01_t_table_column$table_id(input) {
    layer.close(ly_index);
    //查询失败
    if (Call_QryResult(input.N01_t_table_column$table_id) == false)
        return false;
    BEF4F0_ary_TABLE_ID = input.N01_t_table_column$table_id;
    var inputdata = {
        "param_name": "N01_menu_content$menu_id",
        "session_id": session_id,
        "login_id": login_id
    };
    ly_index = layer.load();
    get_ajax_baseurl(inputdata, "BEF4F0_get_N01_menu_content$menu_id");
}

function BEF4F0_get_N01_menu_content$menu_id(input) {
    layer.close(ly_index);
    //查询失败
    if (Call_QryResult(input.N01_menu_content$menu_id) == false)
        return false;
    BEF4F0_ary_TO_URL = input.N01_menu_content$menu_id;
    var inputdata = {
        "param_name": "N01_t_btn_expand$RUN_PROC",
        "session_id": session_id,
        "login_id": login_id
    };
    ly_index = layer.load();
    get_ajax_baseurl(inputdata, "BEF4F0_get_N01_t_btn_expand$RUN_PROC");
}

function BEF4F0_get_N01_t_btn_expand$RUN_PROC(input) {
    layer.close(ly_index);
    //查询失败
    if (Call_QryResult(input.N01_t_btn_expand$RUN_PROC) == false)
        return false;
    BEF4F0_ary_RUN_PROC = input.N01_t_btn_expand$RUN_PROC;

    if($("#BEF4F0_BTN_POS").is("select") && $("#BEF4F0_BTN_POS")[0].options.length == 0)
    {
        $.each(BEF4F0_ary_BTN_POS, function (i, obj) {
            addOptionValue("BEF4F0_BTN_POS", obj[GetLowUpp("main_id")], s_decode(obj[GetLowUpp("cn_name")]));
        });
    }

    if($("#BEF4F0_TO_URL_TYPE").is("select") && $("#BEF4F0_TO_URL_TYPE")[0].options.length == 0)
    {
        $.each(BEF4F0_ary_TO_URL_TYPE, function (i, obj) {
            addOptionValue("BEF4F0_TO_URL_TYPE", obj[GetLowUpp("main_id")], s_decode(obj[GetLowUpp("cn_name")]));
        });
    }
    BEF4F0_init_t_btn_expand();
}

/*biz step end*/

/*查找框函数*/
/*find qry fun begin*/

function BEF4F0_TABLE_ID_cn_name_fun(){
    BEF4F0_btn = "TABLE_ID"
    index_subhtml = "t_single_table.vue";
    random_subhtml = "A12594";
    if(loadHtmlSubVueFun("t_single_table.vue","BEF4F0_t_btn_expand_call_vue") == true){
        var n = Get_RandomDiv("A12594","");
        layer.open({
            type: 1,
            area: ['1100px', '600px'],
            fixed: false, //不固定
            maxmin: true,
            content: $(n),
            success: function(layero, index){
                $('#A12594_t_single_table_Events').bootstrapTable('resetView');
                A12594_param["ly_index"] = index;
                A12594_param["target_name"] = "BEF4F0_find_"+BEF4F0_btn+"_cn_name";
                A12594_param["target_id"] = "BEF4F0_"+BEF4F0_btn;
                A12594_param["sourc_id"] = "MAIN_ID";
                A12594_param["sourc_name"] = "TABLE_EN_NAME";
            },
            end: function(){
                $(n).hide();
            }
        });
     }
}

function BEF4F0_TO_URL_cn_name_fun(){
    BEF4F0_btn = "TO_URL"
    index_subhtml = "dev_vue/v_menu_info.vue";
    random_subhtml = "A55264";
    if(loadHtmlSubVueFun("dev_vue/v_menu_info.vue","BEF4F0_t_btn_expand_call_vue") == true){
        var n = Get_RandomDiv("A55264","");
        layer.open({
            type: 1,
            area: ['1100px', '600px'],
            fixed: false, //不固定
            maxmin: true,
            content: $(n),
            success: function(layero, index){
                $('#A55264_v_menu_info_Events').bootstrapTable('resetView');
                A55264_param["ly_index"] = index;
                A55264_param["target_name"] = "BEF4F0_find_"+BEF4F0_btn+"_cn_name";
                A55264_param["target_id"] = "BEF4F0_"+BEF4F0_btn;
                A55264_param["sourc_id"] = "MENU_URL";
                A55264_param["sourc_name"] = "MENU_URL";
            },
            end: function(){
                $(n).hide();
            }
        });
     }
}

function BEF4F0_RUN_PROC_cn_name_fun(){
    BEF4F0_btn = "RUN_PROC"
    index_subhtml = "dev_vue/v_selproc.vue";
    random_subhtml = "C772A0";
    if(loadHtmlSubVueFun("dev_vue/v_selproc.vue","BEF4F0_t_btn_expand_call_vue") == true){
        var n = Get_RandomDiv("C772A0","");
        layer.open({
            type: 1,
            area: ['1100px', '600px'],
            fixed: false, //不固定
            maxmin: true,
            content: $(n),
            success: function(layero, index){
                $('#C772A0_v_selproc_Events').bootstrapTable('resetView');
                C772A0_param["ly_index"] = index;
                C772A0_param["target_name"] = "BEF4F0_find_"+BEF4F0_btn+"_cn_name";
                C772A0_param["target_id"] = "BEF4F0_"+BEF4F0_btn;
                C772A0_param["sourc_id"] = "INF_EN_NAME";
                C772A0_param["sourc_name"] = "INF_EN_NAME";
            },
            end: function(){
                $(n).hide();
            }
        });
     }
}

/*find qry fun end*/

/*页面结束*/
function BEF4F0_page_end(){
	page_btn_priv("BEF4F0");
	if(BEF4F0_param["type"] == "edit"){
		BEF4F0_get_edit_info();
	}
}

//页面初始化方法
function BEF4F0_init_t_btn_expand() {
	//输入框默认值
	BEF4F0_input_default();
	//参数传递
	BEF4F0_param_set();	
	//表单验证
	BEF4F0_checkFormInput();
	//结束函数
	BEF4F0_page_end();
}

//提交表单数据
function BEF4F0_SubmitForm(){
	if(BEF4F0_param["type"] == "add"){
		var inputdata = {
				"param_name": "N01_ins_t_btn_expand",
				"session_id": session_id,
				"login_id": login_id
	            /*insert param begin*/
                ,"param_value1": $("#BEF4F0_TABLE_ID").val()
                ,"param_value2": s_encode($("#BEF4F0_BTN_EN_NAME").val())
                ,"param_value3": s_encode($("#BEF4F0_BTN_CN_NAME").val())
                ,"param_value4": s_encode($("#BEF4F0_BTN_POS").val())
                ,"param_value5": s_encode($("#BEF4F0_TO_URL").val())
                ,"param_value6": $("#BEF4F0_TO_URL_TYPE").val()
                ,"param_value7": s_encode($("#BEF4F0_TO_URL_PARAM").val())
                ,"param_value8": s_encode($("#BEF4F0_RUN_PROC").val())
                ,"param_value9": s_encode($("#BEF4F0_PROC_PARAM").val())
                ,"param_value10": $("#BEF4F0_S_SORT").val()
                ,"param_value11": $("#BEF4F0_CREATE_DATE").val()
                ,"param_value12": s_encode($("#BEF4F0_S_DESC").val())
				
	            /*insert param end*/
			};
		get_ajax_baseurl(inputdata, "BEF4F0_get_N01_ins_t_btn_expand");
	}
	else if(BEF4F0_param["type"] == "edit"){
		var inputdata = {
				"param_name": "N01_upd_t_btn_expand",
				"session_id": session_id,
				"login_id": login_id
	            /*update param begin*/
                ,"param_value1": $("#BEF4F0_TABLE_ID").val()
                ,"param_value2": s_encode($("#BEF4F0_BTN_EN_NAME").val())
                ,"param_value3": s_encode($("#BEF4F0_BTN_CN_NAME").val())
                ,"param_value4": s_encode($("#BEF4F0_BTN_POS").val())
                ,"param_value5": s_encode($("#BEF4F0_TO_URL").val())
                ,"param_value6": $("#BEF4F0_TO_URL_TYPE").val()
                ,"param_value7": s_encode($("#BEF4F0_TO_URL_PARAM").val())
                ,"param_value8": s_encode($("#BEF4F0_RUN_PROC").val())
                ,"param_value9": s_encode($("#BEF4F0_PROC_PARAM").val())
                ,"param_value10": $("#BEF4F0_S_SORT").val()
                ,"param_value11": $("#BEF4F0_CREATE_DATE").val()
                ,"param_value12": s_encode($("#BEF4F0_S_DESC").val())
                ,"param_value13": $("#BEF4F0_MAIN_ID").val()
				
	            /*update param end*/
			};
		get_ajax_baseurl(inputdata, "BEF4F0_get_N01_upd_t_btn_expand");
	}
}

//vue回调
function BEF4F0_t_btn_expand_call_vue(objResult){
	if(index_subhtml == "XXXXXX")
	{
		
	}
	/*查询条件弹窗子页面*/
    /*get find subvue bgein*/
    else if(index_subhtml == "t_single_table.vue"){
        var n = Get_RandomDiv("A12594",objResult);
        layer.open({
            type: 1,
            area: ['1100px', '600px'],
            fixed: false, //不固定
            maxmin: true,
            content: $(n),
            success: function(layero, index){
                var inputdata = {
                    "type":BEF4F0_type,
                    "ly_index":index,
                    "target_name":"BEF4F0_find_TABLE_ID_cn_name",
                    "target_id":"BEF4F0_TABLE_ID",
                    "sourc_id":"MAIN_ID",
                    "sourc_name":"TABLE_EN_NAME"
                };
                loadScript_hasparam("t_single_table.js","A12594_t_single_table_biz_start",inputdata);
            },
            end: function(){
                $(n).hide();
            }
        });
    }
    else if(index_subhtml == "dev_vue/v_menu_info.vue"){
        var n = Get_RandomDiv("A55264",objResult);
        layer.open({
            type: 1,
            area: ['1100px', '600px'],
            fixed: false, //不固定
            maxmin: true,
            content: $(n),
            success: function(layero, index){
                var inputdata = {
                    "type":BEF4F0_type,
                    "ly_index":index,
                    "target_name":"BEF4F0_find_TO_URL_cn_name",
                    "target_id":"BEF4F0_TO_URL",
                    "sourc_id":"MENU_URL",
                    "sourc_name":"MENU_URL"
                };
                loadScript_hasparam("dev_vue/v_menu_info.js","A55264_v_menu_info_biz_start",inputdata);
            },
            end: function(){
                $(n).hide();
            }
        });
    }
    else if(index_subhtml == "dev_vue/v_selproc.vue"){
        var n = Get_RandomDiv("C772A0",objResult);
        layer.open({
            type: 1,
            area: ['1100px', '600px'],
            fixed: false, //不固定
            maxmin: true,
            content: $(n),
            success: function(layero, index){
                var inputdata = {
                    "type":BEF4F0_type,
                    "ly_index":index,
                    "target_name":"BEF4F0_find_RUN_PROC_cn_name",
                    "target_id":"BEF4F0_RUN_PROC",
                    "sourc_id":"INF_EN_NAME",
                    "sourc_name":"INF_EN_NAME"
                };
                loadScript_hasparam("dev_vue/v_selproc.js","C772A0_v_selproc_biz_start",inputdata);
            },
            end: function(){
                $(n).hide();
            }
        });
    }
	
	/*get find subvue end*/
}

//for表单提交
$("#BEF4F0_save_t_btn_expand_Edit").click(function () {
	$("form[name='BEF4F0_DataModal']").submit();
})

/*修改数据*/
function BEF4F0_get_N01_upd_t_btn_expand(input) {
	layer.close(ly_index);
	if (Call_OpeResult(input.N01_upd_t_btn_expand) == true)
	{
		swal("修改数据成功!", "", "success");
		AEF4F0_t_btn_expand_query();
		BEF4F0_clear_validate();
		layer.close(BEF4F0_param["ly_index"]);
	}
}

/*添加数据*/
function BEF4F0_get_N01_ins_t_btn_expand(input) {
	layer.close(ly_index);
	if (Call_OpeResult(input.N01_ins_t_btn_expand) == true)
	{
		swal("添加数据成功!", "", "success");
		AEF4F0_t_btn_expand_query();
		BEF4F0_clear_validate();
		layer.close(BEF4F0_param["ly_index"]);
	}
}

//取消编辑
$("#BEF4F0_cancel_t_btn_expand_Edit").click(function () {
	layer.close(BEF4F0_param["ly_index"]);
	BEF4F0_clear_validate();
	$("[id^='BEF4F0_div']").hide();
})

//清除查找框
function BEF4F0_clear_input_cn_name(obj1,obj2){
	$("#"+obj1).val("");
	$("#"+obj2).val("-1");
}

//清除验证缓存
function BEF4F0_clear_validate(){
	$("#BEF4F0_DataModal").find(".has-error").each(function(){
		$(this).removeClass('has-error');
	});
	$("#BEF4F0_DataModal").find(".has-success").each(function(){
	 	$(this).removeClass('has-success');
	});
	$("#BEF4F0_DataModal").find(".glyphicon").each(function(){
	 	$(this).remove();
	});
}

//输入框重置
function BEF4F0_clear_edit_info(){
	var inputs = $("#BEF4F0_DataModal").find('input');
	var selects = $("#BEF4F0_DataModal").find("select");
	var textareas = $("#BEF4F0_DataModal").find('textarea');
	$.each(inputs, function (i, obj) {
		$(obj).val("");
	});
	$.each(selects, function (i, obj) {
		$(obj).val("");
	});
	$.each(textareas, function (i, obj) {
		$(obj).val("");
	});
	/*清除输入框验证信息*/
	/*input validate clear begin*/
    BEF4F0_clear_input_cn_name('BEF4F0_find_TABLE_ID_cn_name','BEF4F0_TABLE_ID')
    BEF4F0_clear_input_cn_name('BEF4F0_find_TO_URL_cn_name','BEF4F0_TO_URL')
    BEF4F0_clear_input_cn_name('BEF4F0_find_RUN_PROC_cn_name','BEF4F0_RUN_PROC')
	
	/*input validate clear end*/
	BEF4F0_init_t_btn_expand();
}

//页面输入框赋值
function BEF4F0_get_edit_info(){
	var rowData = $("#AEF4F0_t_btn_expand_Events").bootstrapTable('getData')[AEF4F0_select_t_btn_expand_rowId];
	var inputs = $("#BEF4F0_DataModal").find('input');
	var selects = $("#BEF4F0_DataModal").find("select");
	var textareas = $("#BEF4F0_DataModal").find('textarea');
	
	//通用子页面输入框赋值
	Com_edit_info(rowData,inputs,selects,textareas,"AEF4F0","BEF4F0");
	
	/*文件附件格式*/
	/*input param fileinfo begin*/
	
	/*input param fileinfo end*/
}

//form验证
function BEF4F0_checkFormInput() {
    BEF4F0_validate = $("#BEF4F0_DataModal").validate({
        errorElement: 'span',
        errorClass: 'help-block',
        rules: {
        	/*input check rules begin*/
            BEF4F0_MAIN_ID: {}
            ,BEF4F0_TABLE_ID: {}
            ,BEF4F0_BTN_EN_NAME: {maxlength:50}
            ,BEF4F0_BTN_CN_NAME: {maxlength:50}
            ,BEF4F0_BTN_POS: {maxlength:200}
            ,BEF4F0_TO_URL: {maxlength:500}
            ,BEF4F0_TO_URL_TYPE: {}
            ,BEF4F0_TO_URL_PARAM: {maxlength:500}
            ,BEF4F0_RUN_PROC: {maxlength:50}
            ,BEF4F0_PROC_PARAM: {maxlength:500}
            ,BEF4F0_S_SORT: {digits: true,required : true,maxlength:10}
            ,BEF4F0_CREATE_DATE: {date: true,required : true,maxlength:19}
            ,BEF4F0_S_DESC: {maxlength:500}
			
            /*input check rules end*/
        },
        messages: {
        	/*input check messages begin*/
            BEF4F0_MAIN_ID: {}
            ,BEF4F0_TABLE_ID: {}
            ,BEF4F0_BTN_EN_NAME: {maxlength:"长度不能超过50"}
            ,BEF4F0_BTN_CN_NAME: {maxlength:"长度不能超过50"}
            ,BEF4F0_BTN_POS: {maxlength:"长度不能超过200"}
            ,BEF4F0_TO_URL: {maxlength:"长度不能超过500"}
            ,BEF4F0_TO_URL_TYPE: {}
            ,BEF4F0_TO_URL_PARAM: {maxlength:"长度不能超过500"}
            ,BEF4F0_RUN_PROC: {maxlength:"长度不能超过50"}
            ,BEF4F0_PROC_PARAM: {maxlength:"长度不能超过500"}
            ,BEF4F0_S_SORT: {digits: "必须输入整数",required : "必须输入整数",maxlength:"长度不能超过10" }
            ,BEF4F0_CREATE_DATE: {date: "必须输入正确格式的日期",required : "必须输入正确格式的日期",maxlength:"长度不能超过19"}
            ,BEF4F0_S_DESC: {maxlength:"长度不能超过500"}
			
            /*input check messages end*/
        },
        errorPlacement: function (error, element) {
            element.next().remove();
            element.after('<span class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true"></span>');
            element.closest('.form-group').append(error);
        },
        highlight: function (element) {
            $(element).closest('.form-group').addClass('has-error has-feedback');
        },
        success: function (label) {
            var el = label.closest('.form-group').find("input");
            el.next().remove();
            el.after('<span class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true"></span>');
            label.closest('.form-group').removeClass('has-error').addClass("has-feedback has-success");
            label.remove();
        },
        submitHandler: function (form) {
        	BEF4F0_SubmitForm();
        	return false;
        }
    })
}